package com.example.chatrecommendation.controller;

import com.example.chatrecommendation.bean.dto.ExamResultDTO;
import com.example.chatrecommendation.bean.vo.TDAVO;
import com.example.chatrecommendation.service.impl.StudentRecordServiceImpl;
import com.example.chatrecommendation.tool.JwtUtil;
import com.example.chatrecommendation.tool.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

@RestController
//@CrossOrigin
@RequestMapping("/student/tda")
@Api("学生记录模块")
public class StudentRecordController {
	private static final Logger log = LoggerFactory.getLogger(StudentRecordController.class);
	private final StudentRecordServiceImpl studentRecordServiceImpl;
	private final JwtUtil jwtUtil;

	public StudentRecordController(StudentRecordServiceImpl studentRecordServiceImpl, JwtUtil jwtUtil) {
		this.studentRecordServiceImpl = studentRecordServiceImpl;
		this.jwtUtil = jwtUtil;
	}

	/**
	 * 提交答题数据
	 *
	 * @param examResultDTO 答题数据
	 * @return 是否成功
	 */
	@PostMapping("/submitExamResult")
	@ApiModelProperty("保存答题数据")
	public R<String> examResultSave(@RequestBody ExamResultDTO examResultDTO) {
		log.info("保存答题数据：{}", examResultDTO);
		studentRecordServiceImpl.saveExamResult(examResultDTO, examResultDTO.getUserId());
		return R.success("答题数据保存成功");
	}

	@PostMapping("/submitTDAResult")
	public R<String> saveTdaResult(@RequestParam String tda) {
		studentRecordServiceImpl.saveTdaResult(Double.valueOf(tda));
		return R.success("保存成功");
	}

	/**
	 * 获取tda
	 * 通过学生账号获取tda
	 *
	 * @param stuId 学生账号不是id
	 * @return tda分数
	 */
	@GetMapping("/getTdaResult")
	@ApiModelProperty("获取tda")
	public R<TDAVO> getTdaResult(@RequestParam Integer stuId) {
		TDAVO tda = studentRecordServiceImpl.getTda(stuId);
		return R.success(tda);
	}
}
